/*****************************************************************************

File:   otkCombinedStateInfoExample.java

Date          Build     Author        Version    Comments
18-Sep-12    P-20-14    dshah          $$1        Created
17-Oct-12    P-20-15    dshah          $$2        Updated
20-mar-15 P-30-05 gshmelev $$3  called GetCurrentSession

****************************************************************************/

/* 
   
This example will work on the current Solid (Model/Assembly) as input and do the following: 
- CombinedSate Info: Asks user to enter number refering to "Existing combined Stated" from the list and 
displays that combined state info into Pro/E browser.

*/

package com.ptc.otkjavaexamples;

import com.ptc.cipjava.*;
import com.ptc.pfc.pfcSession.*;
import com.ptc.pfc.pfcCommand.*;
import com.ptc.pfc.pfcGlobal.*;
import com.ptc.pfc.pfcModel.*;
import com.ptc.pfc.pfcModelItem.*;
import com.ptc.pfc.pfcFeature.*;
import com.ptc.pfc.pfcSolid.*;
import javax.swing.JOptionPane;
import java.io.*;

import com.ptc.cipjava.*;
import com.ptc.pfc.pfcFamily.*;
import com.ptc.pfc.pfcServer.*;
import com.ptc.pfc.pfcWindow.*;
import com.ptc.wfc.wfcSolid.*;
import com.ptc.wfc.wfcCombState.*;



// Shows combined state info into Pro/E browser window
class otkCombinedStateInfoExample extends DefaultUICommandActionListener
{
    
    
    
    public otkCombinedStateInfoExample()
    {
    }
    
    
    
    
    public void OnCommand()
    {
	addCombinedStateInfoExample();
    }
    
    
    public int addCombinedStateInfoExample ()
    {
	try
	    {	
		Session session = pfcSession.GetCurrentSession ();
		WSolid WSolid = (WSolid)(session.GetCurrentModel());
		
		CombState WCombState = otkCombStateUtils.otkUtilSelectCombinedState (WSolid, -1);
		
		if(WCombState != null)
		    {
			String InfoFile_name = "CombState_info.txt";
			FileWriter infoFile = new FileWriter (InfoFile_name);
			BufferedWriter fp_InfoFile = new BufferedWriter(infoFile);
			
			// Utility to write combined state info
			otkCombStateUtils.OtkUtilCombinedStateInfo (WSolid, WCombState, fp_InfoFile);
			fp_InfoFile.close();
			
			// Code to display info file into Pro/E browser window
			Window current_win = session.GetCurrentWindow ();
			String line;
			line = "file://";
			line += session.GetCurrentDirectory();
			line += InfoFile_name;
			current_win.SetURL(line);
		    }
		return (0);
		
	    }
	catch (Exception e)
	    {
		System.out.println("1: " + e);
	    }
	return (0);
    }
    
};






